package com.u2b.dispatcher;

import java.util.HashMap;

import javax.annotation.PreDestroy;
import javax.servlet.http.HttpServletRequest;

import com.u2b.business.activity.ActivityService;

public class ActivityDispatcher
{

    private ActivityService activityService;

    public ActivityDispatcher()
    {

        activityService = new ActivityService();

    }

    public Object dispatcer(String action, HashMap<String, Object> initValues, HttpServletRequest request)
    {
        Object obj = null;
        if ("add".equals(action))
        {
            String[] textFormNames = new String[]
            { "owner", "start_time", "display_time", "location", "title", "latitude", "longitude" };
            obj = activityService.createActivity(request, textFormNames);
        }
        else if ("join".equals(action))
        {
            String[] names = new String[]
            { "aid", "uid", "owner" };
            obj = activityService.joinThis(initValues);

        }
        else if ("support".equals(action))
        {
            String[] names = new String[]
            { "aid", "uid", "owner" };
            obj = activityService.supportThis(initValues);

        }
        else if ("comment".equals(action))
        {
            String[] names = new String[]
            { "aid", "uid", "comment_content", "refrence_mid" };
            obj = activityService.commentThis(initValues);

        }
        else if ("list_activities".equals(action))
        {
            String[] names = new String[]
            { "page", "latitude", "longitude" };
            obj = activityService.queryActivityList(initValues);

        }
        else if ("list_comments".equals(action))
        {
            String aid_s = request.getParameter("aid");
            int aid = Integer.valueOf(aid_s);
            obj = activityService.getDetailedMessage(aid);

        }
        else if ("list_joins".equals(action))
        {
            String aid_s = request.getParameter("aid");
            int aid = Integer.valueOf(aid_s);
            obj = activityService.getDetailJoin(aid);

        }
        else if ("list_supports".equals(action))
        {
            String aid_s = request.getParameter("aid");
            int aid = Integer.valueOf(aid_s);
            obj = activityService.getDetailSupport(aid);

        }
        else if ("list_activities".equals(action))
        {
            String[] names = new String[]
            { "page", "latitude", "longitude" };
            obj = activityService.queryActivityList(initValues);

        }
        else if ("list_comments".equals(action))
        {
            String aid_s = request.getParameter("aid");
            int aid = Integer.valueOf(aid_s);
            obj = activityService.getDetailedMessage(aid);

        }
        else if ("list_joins".equals(action))
        {
            String aid_s = request.getParameter("aid");
            int aid = Integer.valueOf(aid_s);
            obj = activityService.getDetailJoin(aid);

        }
        else if ("list_supports".equals(action))
        {
            String aid_s = request.getParameter("aid");
            int aid = Integer.valueOf(aid_s);
            obj = activityService.getDetailJoin(aid);

        }
        return obj;
    }

    @PreDestroy
    public void destory()
    {

        activityService = null;

    }
}
